<template>
  <el-dialog v-drag :title="!dataForm.saleId ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
      label-width="80px">
      <el-form-item label="销售类型 1销售，-1退货" prop="saleType">
        <el-input size="mini" v-model="dataForm.saleType" placeholder="销售类型 1销售，-1退货" clearable></el-input>
      </el-form-item>
      <el-form-item label="销售编号" prop="saleNo">
        <el-input size="mini" v-model="dataForm.saleNo" placeholder="销售编号" clearable></el-input>
      </el-form-item>
      <el-form-item label="销售日期" prop="saleDate">
        <el-input size="mini" v-model="dataForm.saleDate" placeholder="销售日期" clearable></el-input>
      </el-form-item>
      <el-form-item label="退货日期" prop="backDate">
        <el-input size="mini" v-model="dataForm.backDate" placeholder="退货日期" clearable></el-input>
      </el-form-item>
      <el-form-item label="会员id" prop="memberId">
        <el-input size="mini" v-model="dataForm.memberId" placeholder="会员id" clearable></el-input>
      </el-form-item>
      <el-form-item label="会员名称" prop="memberName">
        <el-input size="mini" v-model="dataForm.memberName" placeholder="会员名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="会员编号" prop="memberNo">
        <el-input size="mini" v-model="dataForm.memberNo" placeholder="会员编号" clearable></el-input>
      </el-form-item>
      <el-form-item label="是否挂单" prop="isPending">
        <el-input size="mini" v-model="dataForm.isPending" placeholder="是否挂单" clearable></el-input>
      </el-form-item>
      <el-form-item label="挂单备注" prop="pendingRemark">
        <el-input size="mini" v-model="dataForm.pendingRemark" placeholder="挂单备注" clearable></el-input>
      </el-form-item>
      <el-form-item label="共购买" prop="totalSaleNum">
        <el-input size="mini" v-model="dataForm.totalSaleNum" placeholder="共购买" clearable></el-input>
      </el-form-item>
      <el-form-item label="折前总金额" prop="totalPrediscountFee">
        <el-input size="mini" v-model="dataForm.totalPrediscountFee" placeholder="折前总金额" clearable></el-input>
      </el-form-item>
      <el-form-item label="会员价总金额" prop="totalMemberFee">
        <el-input size="mini" v-model="dataForm.totalMemberFee" placeholder="会员价总金额" clearable></el-input>
      </el-form-item>
      <el-form-item label="折后总金额" prop="totalDiscountFee">
        <el-input size="mini" v-model="dataForm.totalDiscountFee" placeholder="折后总金额" clearable></el-input>
      </el-form-item>
      <el-form-item label="定点医保基金支付金额" prop="fundPaySumamt">
        <el-input size="mini" v-model="dataForm.fundPaySumamt" placeholder="定点医保基金支付金额" clearable></el-input>
      </el-form-item>
      <el-form-item label="其它费用总额" prop="toalOtherFee">
        <el-input size="mini" v-model="dataForm.toalOtherFee" placeholder="其它费用总额" clearable></el-input>
      </el-form-item>
      <el-form-item label="实付金额" prop="paymentFee">
        <el-input size="mini" v-model="dataForm.paymentFee" placeholder="实付金额" clearable></el-input>
      </el-form-item>
      <el-form-item label="实收金额" prop="receiveFee">
        <el-input size="mini" v-model="dataForm.receiveFee" placeholder="实收金额" clearable></el-input>
      </el-form-item>
      <el-form-item label="找零金额" prop="giveChangeFee">
        <el-input size="mini" v-model="dataForm.giveChangeFee" placeholder="找零金额" clearable></el-input>
      </el-form-item>
      <el-form-item label="共优惠(元)" prop="totalReduceFee">
        <el-input size="mini" v-model="dataForm.totalReduceFee" placeholder="共优惠(元)" clearable></el-input>
      </el-form-item>
      <el-form-item label="共赠送数量" prop="totalGiveNum">
        <el-input size="mini" v-model="dataForm.totalGiveNum" placeholder="共赠送数量" clearable></el-input>
      </el-form-item>
      <el-form-item label="是否支付" prop="isPayed">
        <el-input size="mini" v-model="dataForm.isPayed" placeholder="是否支付" clearable></el-input>
      </el-form-item>
      <el-form-item label="支付类型 1:现金，2:支付宝,3:微信,4:社保卡,5:银联,6:其它" prop="payType">
        <el-input size="mini" v-model="dataForm.payType" placeholder="支付类型 1:现金，2:支付宝,3:微信,4:社保卡,5:银联,6:其它" clearable>
        </el-input>
      </el-form-item>
      <el-form-item label="营业员id" prop="sellerId">
        <el-input size="mini" v-model="dataForm.sellerId" placeholder="营业员id" clearable></el-input>
      </el-form-item>
      <el-form-item label="营业员名称" prop="sellUser">
        <el-input size="mini" v-model="dataForm.sellUser" placeholder="营业员名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="购买人" prop="buyerName">
        <el-input size="mini" v-model="dataForm.buyerName" placeholder="购买人" clearable></el-input>
      </el-form-item>
      <el-form-item label="购买人身份证号码" prop="buyerCardId">
        <el-input size="mini" v-model="dataForm.buyerCardId" placeholder="购买人身份证号码" clearable></el-input>
      </el-form-item>
      <el-form-item label="购买人手机号" prop="buyerMobile">
        <el-input size="mini" v-model="dataForm.buyerMobile" placeholder="购买人手机号" clearable></el-input>
      </el-form-item>
      <el-form-item label="优惠券Id" prop="couponId">
        <el-input size="mini" v-model="dataForm.couponId" placeholder="优惠券Id" clearable></el-input>
      </el-form-item>
      <el-form-item label="单张金额" prop="singleFee">
        <el-input size="mini" v-model="dataForm.singleFee" placeholder="单张金额" clearable></el-input>
      </el-form-item>
      <el-form-item label="购买都 人脸id" prop="buyerFaceId">
        <el-input size="mini" v-model="dataForm.buyerFaceId" placeholder="购买都 人脸id" clearable></el-input>
      </el-form-item>
      <el-form-item label="退货状态 0 或null：表示没退货, 1:表示部分退货, 2: 表示完成退货" prop="backType">
        <el-input size="mini" v-model="dataForm.backType" placeholder="退货状态 0 或null：表示没退货, 1:表示部分退货, 2: 表示完成退货"
          clearable></el-input>
      </el-form-item>
      <el-form-item label="订单来源：1POS，2小程序" prop="orderSource">
        <el-input size="mini" v-model="dataForm.orderSource" placeholder="订单来源：1POS，2小程序" clearable></el-input>
      </el-form-item>
      <el-form-item label="0:线下支付， 1：线上支付" prop="isOnlinePay">
        <el-input size="mini" v-model="dataForm.isOnlinePay" placeholder="0:线下支付， 1：线上支付" clearable></el-input>
      </el-form-item>
      <el-form-item label="门店id" prop="storeId">
        <el-input size="mini" v-model="dataForm.storeId" placeholder="门店id" clearable></el-input>
      </el-form-item>
      <el-form-item label="门店名称" prop="storeName">
        <el-input size="mini" v-model="dataForm.storeName" placeholder="门店名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="门店编码" prop="storeCode">
        <el-input size="mini" v-model="dataForm.storeCode" placeholder="门店编码" clearable></el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-input size="mini" v-model="dataForm.createTime" placeholder="创建时间" clearable></el-input>
      </el-form-item>
      <el-form-item label="修改时间" prop="updateTime">
        <el-input size="mini" v-model="dataForm.updateTime" placeholder="修改时间" clearable></el-input>
      </el-form-item>
      <el-form-item label="创建人" prop="createUsername">
        <el-input size="mini" v-model="dataForm.createUsername" placeholder="创建人" clearable></el-input>
      </el-form-item>
      <el-form-item label="创建人id" prop="createUserId">
        <el-input size="mini" v-model="dataForm.createUserId" placeholder="创建人id" clearable></el-input>
      </el-form-item>
      <el-form-item label="修改人" prop="updateUsername">
        <el-input size="mini" v-model="dataForm.updateUsername" placeholder="修改人" clearable></el-input>
      </el-form-item>
      <el-form-item label="修改人id" prop="updateUserId">
        <el-input size="mini" v-model="dataForm.updateUserId" placeholder="修改人id" clearable></el-input>
      </el-form-item>
      <el-form-item label="是否可用 1:是" prop="status">
        <el-input size="mini" v-model="dataForm.status" placeholder="是否可用 1:是" clearable></el-input>
      </el-form-item>
      <el-form-item label="版本" prop="version">
        <el-input size="mini" v-model="dataForm.version" placeholder="版本" clearable></el-input>
      </el-form-item>
      <el-form-item label="是否删除 1:是" prop="isDeleted">
        <el-input size="mini" v-model="dataForm.isDeleted" placeholder="是否删除 1:是" clearable></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input size="mini" v-model="dataForm.remark" placeholder="备注" clearable></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          saleId: 0,
          saleType: '',
          saleNo: '',
          saleDate: '',
          backDate: '',
          memberId: '',
          memberName: '',
          memberNo: '',
          isPending: '',
          pendingRemark: '',
          totalSaleNum: '',
          totalPrediscountFee: '',
          totalMemberFee: '',
          totalDiscountFee: '',
          fundPaySumamt: '',
          toalOtherFee: '',
          paymentFee: '',
          receiveFee: '',
          giveChangeFee: '',
          totalReduceFee: '',
          totalGiveNum: '',
          isPayed: '',
          payType: '',
          sellerId: '',
          sellUser: '',
          buyerName: '',
          buyerCardId: '',
          buyerMobile: '',
          couponId: '',
          singleFee: '',
          buyerFaceId: '',
          backType: '',
          orderSource: '',
          isOnlinePay: '',
          storeId: '',
          storeName: '',
          storeCode: '',
          createTime: '',
          updateTime: '',
          createUsername: '',
          createUserId: '',
          updateUsername: '',
          updateUserId: '',
          status: '',
          version: '',
          isDeleted: '',
          remark: ''
        },
        dataRule: {
          saleType: [{
            required: true,
            message: '销售类型 1销售，-1退货不能为空',
            trigger: 'blur'
          }],
          saleNo: [{
            required: true,
            message: '销售编号不能为空',
            trigger: 'blur'
          }],
          saleDate: [{
            required: true,
            message: '销售日期不能为空',
            trigger: 'blur'
          }],
          backDate: [{
            required: true,
            message: '退货日期不能为空',
            trigger: 'blur'
          }],
          memberId: [{
            required: true,
            message: '会员id不能为空',
            trigger: 'blur'
          }],
          memberName: [{
            required: true,
            message: '会员名称不能为空',
            trigger: 'blur'
          }],
          memberNo: [{
            required: true,
            message: '会员编号不能为空',
            trigger: 'blur'
          }],
          isPending: [{
            required: true,
            message: '是否挂单不能为空',
            trigger: 'blur'
          }],
          pendingRemark: [{
            required: true,
            message: '挂单备注不能为空',
            trigger: 'blur'
          }],
          totalSaleNum: [{
            required: true,
            message: '共购买不能为空',
            trigger: 'blur'
          }],
          totalPrediscountFee: [{
            required: true,
            message: '折前总金额不能为空',
            trigger: 'blur'
          }],
          totalMemberFee: [{
            required: true,
            message: '会员价总金额不能为空',
            trigger: 'blur'
          }],
          totalDiscountFee: [{
            required: true,
            message: '折后总金额不能为空',
            trigger: 'blur'
          }],
          fundPaySumamt: [{
            required: true,
            message: '定点医保基金支付金额不能为空',
            trigger: 'blur'
          }],
          toalOtherFee: [{
            required: true,
            message: '其它费用总额不能为空',
            trigger: 'blur'
          }],
          paymentFee: [{
            required: true,
            message: '实付金额不能为空',
            trigger: 'blur'
          }],
          receiveFee: [{
            required: true,
            message: '实收金额不能为空',
            trigger: 'blur'
          }],
          giveChangeFee: [{
            required: true,
            message: '找零金额不能为空',
            trigger: 'blur'
          }],
          totalReduceFee: [{
            required: true,
            message: '共优惠(元)不能为空',
            trigger: 'blur'
          }],
          totalGiveNum: [{
            required: true,
            message: '共赠送数量不能为空',
            trigger: 'blur'
          }],
          isPayed: [{
            required: true,
            message: '是否支付不能为空',
            trigger: 'blur'
          }],
          payType: [{
            required: true,
            message: '支付类型 1:现金，2:支付宝,3:微信,4:社保卡,5:银联,6:其它不能为空',
            trigger: 'blur'
          }],
          sellerId: [{
            required: true,
            message: '营业员id不能为空',
            trigger: 'blur'
          }],
          sellUser: [{
            required: true,
            message: '营业员名称不能为空',
            trigger: 'blur'
          }],
          buyerName: [{
            required: true,
            message: '购买人不能为空',
            trigger: 'blur'
          }],
          buyerCardId: [{
            required: true,
            message: '购买人身份证号码不能为空',
            trigger: 'blur'
          }],
          buyerMobile: [{
            required: true,
            message: '购买人手机号不能为空',
            trigger: 'blur'
          }],
          couponId: [{
            required: true,
            message: '优惠券Id不能为空',
            trigger: 'blur'
          }],
          singleFee: [{
            required: true,
            message: '单张金额不能为空',
            trigger: 'blur'
          }],
          buyerFaceId: [{
            required: true,
            message: '购买都 人脸id不能为空',
            trigger: 'blur'
          }],
          backType: [{
            required: true,
            message: '退货状态 0 或null：表示没退货, 1:表示部分退货, 2: 表示完成退货不能为空',
            trigger: 'blur'
          }],
          orderSource: [{
            required: true,
            message: '订单来源：1POS，2小程序不能为空',
            trigger: 'blur'
          }],
          isOnlinePay: [{
            required: true,
            message: '0:线下支付， 1：线上支付不能为空',
            trigger: 'blur'
          }],
          storeId: [{
            required: true,
            message: '门店id不能为空',
            trigger: 'blur'
          }],
          storeName: [{
            required: true,
            message: '门店名称不能为空',
            trigger: 'blur'
          }],
          storeCode: [{
            required: true,
            message: '门店编码不能为空',
            trigger: 'blur'
          }],
          createTime: [{
            required: true,
            message: '创建时间不能为空',
            trigger: 'blur'
          }],
          updateTime: [{
            required: true,
            message: '修改时间不能为空',
            trigger: 'blur'
          }],
          createUsername: [{
            required: true,
            message: '创建人不能为空',
            trigger: 'blur'
          }],
          createUserId: [{
            required: true,
            message: '创建人id不能为空',
            trigger: 'blur'
          }],
          updateUsername: [{
            required: true,
            message: '修改人不能为空',
            trigger: 'blur'
          }],
          updateUserId: [{
            required: true,
            message: '修改人id不能为空',
            trigger: 'blur'
          }],
          status: [{
            required: true,
            message: '是否可用 1:是不能为空',
            trigger: 'blur'
          }],
          version: [{
            required: true,
            message: '版本不能为空',
            trigger: 'blur'
          }],
          isDeleted: [{
            required: true,
            message: '是否删除 1:是不能为空',
            trigger: 'blur'
          }],
          remark: [{
            required: true,
            message: '备注不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      init(id) {
        this.dataForm.saleId = id || 0
        this.visible = true
        this.$nextTick(async () => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.saleId) {
            const res = await this.$http({
              url: `/sale/saleorder/info/${this.dataForm.saleId}`,
              method: 'get',
              params: this.$http.adornParams()
            })
            let data = res.data
            if (data && data.code === 0) {
              this.dataForm = data.saleOrder
            }
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate(async (valid) => {
          if (valid) {
            const res = await this.$http({
              url: `/sale/saleorder/${!this.dataForm.saleId ? 'save' : 'update'}`,
              method: 'post',
              data: this.$http.adornData(this.dataForm)
            })
            let data = res.data
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          }
        })
      }
    }
  }
</script>
